package com.atguigu.exer;
//使用同步方法来解决实现Runnable接口的线程安全问题
public class WindowsTest1 implements Runnable{
    private int ticket=1000;

    public static void main(String[] args) {
        WindowsTest2 wt1=new WindowsTest2();
        Thread thread1=new Thread(wt1);
        Thread thread2=new Thread(wt1);
        Thread thread3=new Thread(wt1);
        thread1.setName("窗口1");
        thread2.setName("窗口2");
        thread3.setName("窗口3");
        thread1.start();
        thread2.start();
        thread3.start();
    }

    public void run(){
        while(true){
            show();
        }
    }
    private synchronized void show(){
        if(ticket>0){
            System.out.println(Thread.currentThread().getName()+":卖票，票号为:"+ticket);
            ticket--;
        }
    }

}
